import { defineStore } from "pinia";

export const useUserInfo = defineStore("user", {
    state: () => {
        return {
            token: "",
            user_id: "",
            user_avator: "",
            user_nick_name: "",
            user_look: "",
        };
    },
    getters: {
        lookLength(state) {
            if (state.user_look != "") {
                let l = state.user_look.split(",");
                return l.length;
            }
            return 0;
        },
    },
    actions: {
        getToken(value: string) {
            this.$state.token = value;
        },
        getInfo(value: any) {
            this.user_id = value.user_id;
            this.user_avator = value.user_avator;
            this.user_nick_name = value.user_nick_name;
        },
        getUserLook(value: any) {
            // let v = JSON.parse(value);
            // console.log(value);
            this.user_look = value;
        },
    },
});
